<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主持人管理')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="host-form">
                <div class="select-list">
                    <ul>
                        <li>
                            姓名：<input type="text" name="hostName"/>
                        </li>
                        <li>
                            账号状态：<select name="hostState" th:with="type=${@dict.getType('sys_normal_disable')}">
                            <option value="-1">请选择</option>
                            <option value="1">正常</option>
                            <option value="2">禁用</option>
                        </select>
                        </li>
                        <li>
                            排序方式：<select name="hostOrderNum" th:with="type=${@dict.getType('sys_normal_disable')}">
                            <option value="-1">请选择</option>
                            <option value="1">订单量降序</option>
                            <option value="2">订单量升序</option>
                            <option value="3">权重降序</option>
                            <option value="4">权重升序</option>

                        </select>
                        </li>
                        <li>
                            星推荐：<select name="hostRecommend" th:with="type=${@dict.getType('sys_normal_disable')}">
                            <option value="-1">请选择</option>
                            <option value="1">推荐</option>
                            <option value="0">不推荐</option>
                        </select>
                        </li>
                        <li>
                            折扣：<select name="hostDiscount" th:with="type=${@dict.getType('sys_normal_disable')}">
                            <option value="-1">请选择</option>
                            <option value="">有折扣</option>
                            <option value="">无折扣</option>

                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="user:host:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="user:host:update">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="user:host:delete">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="user:host:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('user:host:update')}]];
    var removeFlag = [[${@permission.hasPermi('user:hostremove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "user/host";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "hostName",
            sortName: "hostSortWeight",
            sortOrder: "desc",
            modalName: "主持人",
            columns: [{
                checkbox: true
            },
                {
                    field: 'hostId',
                    title: '主键'
                },
                {
                    field: 'hostSortWeight',
                    title: '权重',
                    formatter: function (value, row, index) {
                        return "<input type='text' size='3' onblur='checkHostSortWeight(this)' " +
                            "onfocus='getHostSortWeight(this)'  value='" + value + "'/>";
                    }
                },
                {
                    field: 'hostName',
                    title: '姓名'
                },
                {
                    field: 'hostPhone',
                    title: '手机号'
                },
                {
                    field: 'hostRegtime',
                    title: '开通时间'
                },
                {
                    field: 'hostPrice',
                    title: '价格'
                },
                {
                    //field: 'hostRegtime',
                    title: '订单量'
                },
                {
                    //field: 'hostRegtime',
                    title: '折扣'
                },
                {
                    field: 'hostRecommend',
                    title: '星推荐',
                    formatter: function (value, row, index) {
                        if (value == "0") {
                            return "<span style='color: red'>否</span>";
                        }
                        return "是";
                    }
                },
                {
                    field: 'hostPstate',
                    title: '账号状态',
                    formatter: function (value, row, index) {
                        if (value == "2") {
                            return "<span style='color: red'>禁用</span>>";
                        }
                        return "正常";
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.postId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //获取焦点时 得到权重的值
    var oldSortWeight = 100;

    function getHostSortWeight(obj) {
        oldSortWeight = $(obj).val();
    }

    function checkHostSortWeight(sortWeight) {
        var weights = $(sortWeight).val();
        //判断是否为数字
        if (isNaN(weights) == false) {
            var weightInt = parseInt(weights);
            //判断时否为小数 如果有小数返回false
            if (weightInt == parseFloat(weights)) {

                //判断该值是否在取值范围内
                if (weightInt >= 0 && weightInt <= 100) {

                    //获取主持人id值
                    var hostId = $(sortWeight).parent().prev().html();

                    $.post(prefix + "/update/sortWeight", {
                        hostSortWeight: weightInt,
                        hostId: hostId
                    }, function (result) {

                        if (result.code == 0) {
                            $.table.refresh();
                        }
                    })
                } else {
					$.modal.alertWarning("输入的值不在取值范围内")
                    //如果不是数字将值换成获取焦点时得到的值
                    $(sortWeight).val(oldSortWeight);
                }
            } else {
				$.modal.alertWarning("输入的值不能为小数")
                //如果不是数字将值换成获取焦点时得到的值
                $(sortWeight).val(oldSortWeight);
            }


        } else {
            $.modal.alertWarning("请输入数字")
            //如果不是数字将值换成获取焦点时得到的值
            $(sortWeight).val(oldSortWeight);

        }


    }

</script>
</body>
</html>